<div class="container">
    <h1 id="pkg-overview">package cookiejar</h1>
    <p><code>import "net/http/cookiejar"</code>
    </p><p>cookiejar包实现了保管在内存中的符合<a href="http://tools.ietf.org/html/rfc6265">RFC 6265标准的</a>http.CookieJar接口。</p>
    
    
		
        
        
        
        
    
    <h2 id="PublicSuffixList">type <a href="https://github.com/golang/go/blob/master/src/net/http/cookiejar/jar.go?name=release#34" title="View Source">PublicSuffixList</a> </h2>
    <pre>type PublicSuffixList interface {
    <span class="com">// 返回域名的公共后缀。</span><span class="com"></span>
    <span class="com">// TODO：域名的格式化应该由调用者还是接口方法负责还没有确定。</span>
    <span id="PublicSuffixList.PublicSuffix">PublicSuffix</span>(domain <a href="builtin.htm#string">string</a>) <a href="builtin.htm#string">string</a>
    <span class="com">// 返回公共后缀列表的来源的说明，该说明一般应该包含时间戳和版本号。</span><span class="com"></span>
    <span id="PublicSuffixList.String">String</span>() <a href="builtin.htm#string">string</a>
}</pre>
    <p>PublicSuffixList提供域名的公共后缀。例如：</p>
    <pre>- "example.com"的公共后缀是"com"
- "foo1.foo2.foo3.co.uk"的公共后缀是"co.uk"
- "bar.pvt.k12.ma.us"的公共后缀是"pvt.k12.ma.us"</pre>
    <p>PublicSuffixList接口的实现必须是并发安全的。一个总是返回""的实现是合法的，也可以通过测试；但却是不安全的：它允许HTTP服务端跨域名设置cookie。推荐实现：<a href="http://godoc.org/code.google.com/p/go.net/publicsuffix">code.google.com/p/go.net/publicsuffix</a></p>
    <h2 id="Options">type <a href="https://github.com/golang/go/blob/master/src/net/http/cookiejar/jar.go?name=release#49" title="View Source">Options</a> </h2>
    <pre>type Options struct {
    <span class="com">// PublicSuffixList是公共后缀列表，用于决定HTTP服务端是否能给某域名设置cookie</span>
    <span class="com">// nil值合法的，也可以通过测试；但却是不安全的：它允许HTTP服务端跨域名设置cookie</span><span class="com"></span>
    <span id="Options.PublicSuffixList">PublicSuffixList</span> <a href="#PublicSuffixList">PublicSuffixList</a>
}</pre>
    <p>Options是创建新Jar是的选项。</p>
    <h2 id="Jar">type <a href="https://github.com/golang/go/blob/master/src/net/http/cookiejar/jar.go?name=release#60" title="View Source">Jar</a> </h2>
    <pre>type Jar struct {
    <span class="com">// 内含隐藏或非导出字段</span>
}</pre>
    <p>Jar类型实现了net/http包的http.CookieJar接口。</p>
    <h3 id="New">func <a href="https://github.com/golang/go/blob/master/src/net/http/cookiejar/jar.go?name=release#77" title="View Source">New</a> </h3>
    <pre class="funcdecl">func New(o *<a href="#Options">Options</a>) (*<a href="#Jar">Jar</a>, <a href="builtin.htm#error">error</a>)</pre>
    <p>返回一个新的Jar，nil指针等价于Options零值的指针。</p>
    <h3 id="Jar.Cookies">func (*Jar) <a href="https://github.com/golang/go/blob/master/src/net/http/cookiejar/jar.go?name=release#171" title="View Source">Cookies</a> </h3>
    <pre class="funcdecl">func (j *<a href="#Jar">Jar</a>) Cookies(u *<a href="net/url.htm">url</a>.<a href="net/url.htm#URL">URL</a>) (cookies []*<a href="net/http.htm">http</a>.<a href="net/http.htm#Cookie">Cookie</a>)</pre>
    <p>实现CookieJar接口的Cookies方法，如果URL协议不是HTTP/HTTPS会返回空切片。</p>
    <h3 id="Jar.SetCookies">func (*Jar) <a href="https://github.com/golang/go/blob/master/src/net/http/cookiejar/jar.go?name=release#235" title="View Source">SetCookies</a> </h3>
    <pre class="funcdecl">func (j *<a href="#Jar">Jar</a>) SetCookies(u *<a href="net/url.htm">url</a>.<a href="net/url.htm#URL">URL</a>, cookies []*<a href="net/http.htm">http</a>.<a href="net/http.htm#Cookie">Cookie</a>)</pre>
    <p>实现CookieJar接口的SetCookies方法，如果URL协议不是HTTP/HTTPS则不会有实际操作。</p>
</div>